#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=305;
int n,a[N],f[N][N][N];
inline int dfs(int l,int r,int x){
	if(~f[l][r][x]) return f[l][r][x];
	if(l==r) return a[l]!=x;
	f[l][r][x]=min({
		dfs(l+1,r,x+1)+(a[l]!=x),dfs(l+1,r,x)+(a[l]!=x+r-l),
		dfs(l,r-1,x+1)+(a[r]!=x),dfs(l,r-1,x)+(a[r]!=x+r-l)
	});
	return f[l][r][x];
}
signed main(){
	freopen("build.in","r",stdin);
	freopen("build.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n,memset(f,-1,sizeof f);
	for(int i=1;i<=n;++i) cin>>a[i];
	cout<<dfs(1,n,1)<<"\n";
}